package org.egedede.commons.ui;

import java.awt.event.ActionEvent;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;

import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public abstract class EAbstractAction extends AbstractAction {

	private static final long serialVersionUID = 4329021121979032426L;

	public EAbstractAction(final String label) {
		super(label);
	}

	public EAbstractAction(final String name, final Icon icon) {
		super(name, icon);
	}

	public void actionPerformed(final ActionEvent arg0) {
		try {
			this.perform();
		} catch (final Exception e) {
			final ByteArrayOutputStream baos = new ByteArrayOutputStream();
			final PrintWriter w = new PrintWriter(baos);
			e.printStackTrace(w);
			w.flush();
			e.printStackTrace();
			final JTextArea area = new JTextArea(baos.toString());

			JOptionPane.showMessageDialog(null, new JScrollPane(area));
		}
	}

	public abstract void perform();
}
